<?php

namespace app\common\model;

use think\Cache;
use think\Model;

class Agent extends Model
{

    // 表名
    protected $name = 'agent_info';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
    ];


    public static function AgentName($Id)
    {
        if(!$userlist = Cache::get('AGENT_NAME'))
        {
            $userlist = collection(Agent::field("id,agent_name")->select())->toArray();
            $userlist = array_column($userlist,null,'id');
            Cache::set('AGENT_NAME',$userlist,604800);//有效期一个星期
        }
        return $userlist[$Id]['agent_name'];
    }

    //获取有效的代理商列表
    public static function AgentList()
    {
        if(!$userlist = Cache::get('AGENT_LIST'))
        {
            $userlist = collection(Agent::field("id,agent_name,agent_region")->select())->toArray();
            $userlist = array_column($userlist,null,'id');
            Cache::set('AGENT_LIST',$userlist,604800);//有效期一个星期
        }
        return $userlist;
    }

}
